package com.example.demo.controller;

import com.example.demo.model.Information;

import com.example.demo.service.InformationService;
import com.example.demo.tool.ResponseMessage;
import com.example.demo.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * 编写人：常静茹
 *
 * */

@RestController("/Information")
public class InformationController {

    @Autowired
    private InformationService informationService;



    @CrossOrigin
    @RequestMapping(value = "/getOneInf")
    public Information getOneInf(Integer iid){
        return informationService.selectByPrimaryKey(iid);
    }

   @CrossOrigin
    @RequestMapping(value = "/getEnterPrise")
    public List<Information> getEnterPrise(){
        System.out.println("调用角色全部类型的接口");
        List<Information> listInformation = informationService.getEnterprise();
        return listInformation;
    }

    @CrossOrigin
    @RequestMapping(value = "/getAllInf")
    public ResponseMessage getAllInf(){
        System.out.println("调用公司全部信息的方法");
        Map<String,List> map=new HashMap<>();
        List<Information> informations = informationService.getAllInf();
        map.put("list",informations);
        return Result.success("200",map);
    }

    @CrossOrigin
    @RequestMapping(value = "/delInformation",method = RequestMethod.GET)
    public int delInformation(Integer iid){
        return informationService.delInformation(iid);
    }

    @CrossOrigin
    @RequestMapping(value = "/addInformation",method = RequestMethod.PUT)
    public int addInformation(@RequestBody Information informationmodel) {
        //判断传入参数是否为空
        if (informationmodel!=null){

        }else {

        }
        return informationService.insertInformation(informationmodel);
    }

    @CrossOrigin
    @RequestMapping(value = "/editInformation",method = RequestMethod.PUT)
    public int editInformation(@RequestBody Information informationmodel) {
        //判断传入参数是否为空
        if (informationmodel!=null){

        }else {

        }
        return informationService.editInformation(informationmodel);
    }

}
